package com.hooda.controller;

import com.hooda.pojo.Employee;
import com.hooda.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhangzp
 * @version 1.0, 2021/9/30
 */
@RestController
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @RequestMapping("/emp/{id}")
    public Employee getEmp(@PathVariable("id") Integer id) {
        return employeeService.getEmployeeById(id);
    }

    @RequestMapping("/emp/update/{id}/{name}")
    public Employee updateEmp(@PathVariable("id") Integer id, @PathVariable("name") String name) {
        Employee entity = employeeService.getEmployeeById(id);
        entity.setLastName(name);
        return employeeService.updateEmployee(entity);
    }

    @RequestMapping("/emp/delete/{id}")
    public Employee deleteEmp(@PathVariable("id") Integer id) {
        employeeService.deleteEmployee(id);
        return null;
    }
}
